import React, { useState } from 'react';
interface AppStateValue {
    username: string;
    shoppingCart: { items: { id: number; name: string; }[] }
}
const defaultContextValue: AppStateValue = {
    username: 'lyr888',
    shoppingCart: {
        items: []
    }
};
export const appContext = React.createContext(defaultContextValue)
export const appSetStateContext = React.createContext<React.Dispatch<React.SetStateAction<AppStateValue>> | undefined>(undefined)

const AppContextProvider: React.FC = (props) => {
    const [state, setState] = useState(defaultContextValue)
    // setTimeout(() => {
    //     setState({
    //         username: 'lyr999',
    //         shoppingCart: {
    //             items: []
    //         }
    //     })
    // }, 3000);
    return (
        <appContext.Provider value={state}>
            <appSetStateContext.Provider value={setState}>
                {props.children}
            </appSetStateContext.Provider>
        </appContext.Provider>
    )
}
export default AppContextProvider;